/**
 * 登录设置管理工具
 */

// 默认登录设置
const defaultLoginSettings = {
  enableCaptcha: true,
  captchaLength: 4,
  captchaType: 'alphanumeric',
  caseSensitive: false
}

// 获取登录设置
export function getLoginSettings() {
  try {
    const savedSettings = localStorage.getItem('loginSettings')
    if (savedSettings) {
      return { ...defaultLoginSettings, ...JSON.parse(savedSettings) }
    }
  } catch (error) {
    console.error('获取登录设置失败:', error)
  }
  return { ...defaultLoginSettings }
}

// 保存登录设置
export function saveLoginSettings(settings) {
  try {
    localStorage.setItem('loginSettings', JSON.stringify(settings))
    return true
  } catch (error) {
    console.error('保存登录设置失败:', error)
    return false
  }
}

// 重置登录设置
export function resetLoginSettings() {
  try {
    localStorage.removeItem('loginSettings')
    return true
  } catch (error) {
    console.error('重置登录设置失败:', error)
    return false
  }
}

// 检查是否启用验证码
export function isCaptchaEnabled() {
  const settings = getLoginSettings()
  return settings.enableCaptcha
}

// 获取验证码配置
export function getCaptchaConfig() {
  const settings = getLoginSettings()
  return {
    length: settings.captchaLength,
    type: settings.captchaType,
    caseSensitive: settings.caseSensitive
  }
} 